<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>新增合同配送</title>
	<link rel="stylesheet" href="css/reset.css">
	<link rel="stylesheet" href="css/product.css">
	<link rel="stylesheet" href="css/select-big.css">
	<link rel="stylesheet" href = "css/fuzzy-query.css">
	<style>
		.content-btn {
		    margin: 0 16px;
		}
		.product-child-content{
			width: 970px;
			margin: 0 auto;
		}
		.product-child-content .content-btn {
		    margin: 0;
		}
		.content-table-two tbody tr td input{
			width: 80%;
			height: 30px;
			line-height: 30px;
			background: #F9FBFF;
			border: 1px solid #ecf2f7;
			border-radius: 15px;
			text-align: center;
		}
		.icon-delImg{
			display: inline-block;
		    background: url(images/close-1.png)no-repeat;
		    width: 25px;
		    height: 25px;
		    cursor: pointer;
		}
		.icon-delImg:hover{
			background: url(images/close-1.png)no-repeat 0 -27px;
		}
	</style>
</head>
<body>
<div class="main-content">
	<form dataHref = "/expressInformation/save">
		<input type = "hidden" name = "type" value = "0">
		<div class="main-bg1">
			<div class="content-btn bot-line">
				<a class="icon-back" href="contractDistribution.html"></a><span class="title-info-a">配送</span>
			</div>
			<div class="content-list">
				<table class="content-table-newservice" cellspacing="0" cellpadding="0">
					<tbody>
						<tr>
							<td><span class="info-red"><font color="red">*</font>收件人部门：</span></td>
							<td>
								<div class = "fuzzy-query" dataUrl = "/org/selectAllDeptTree" dataname = "departmentname" datavalue = addressee lablename = "parentName" valuename = "parentId"></div>
							</td>
						</tr>
						<tr>
							<td><span class="info-red"><font color="red">*</font>快递公司：</span></td>
							<td><select id="single2" name = "company">
								<option value="1">顺丰快递</option>
								<option value="2">圆通快递</option>
								<option value="3">申通快递</option>
								<option value="4">韵达快递</option>
								<option value="5">汇通快递</option>
								<option value="6">邮政EMS</option>
								<option value="7">自取</option>
							</select></td>
						</tr>
						<tr>
							<td><span class="info-red"><font color="red">*</font>快递单号：</span></td>
							<td><input type="text" name = "tracknumber" class = "required" ></td>
						</tr>
						<tr>
							<td><span class="info-red"><font color="red">*</font>印刷厂：</span></td>
							<td><select id="single3" name = "printers">
								<option value="1">杭州印刷厂</option>
								<option value="2">廊坊印刷厂</option>
								<option value="3">总部发放</option>
							</select></td>
						</tr>
						<tr>
							<td>描述：</td>
							<td><textarea name="" id="" cols="30" rows="3" name = "remark"></textarea></td>
						</tr>
					</tbody>
				</table>
			</div>
			<div class="product-child-content">
				<div class="content-info">
					<div class="content-btn bot-line">
						<span class="title-info">纸质合同信息</span>
					</div>
					<table class="tableOrder content-table-two matop" cellspacing="0" cellpadding="0">
						<thead>
							<tr>
								<td style="width:100px;">项目编号</td>
								<td style="width:250px;">项目名称</td>
								<td style="width:100px;">需配送数量</td>
								<td style="width:100px;">可配送数量</td>
								<td style="width:100px;">本次配送数量</td>
								<td style="width:150px;">合同编号</td>
								<td style="width:100px;">操作</td>
							</tr>
						</thead>
						<tbody id = "pre">
						</tbody>
					</table>
					<button class="save-btn matop">保存</button>
				</div>
			</div>
		</div>
	</form>
</div>
	<script src="js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
	<script src="js/select.jquery.js"></script>
	<script type="text/javascript" src = "js/util.js"></script>
	<script type="text/javascript" src = "js/table.js"></script>
	<script type="text/javascript" src = "js/fuzzy-query.js"></script>
	<script type="text/javascript" src = "js/allProduct.js"></script>
	<script>
		function getHeight(){
		var myiframeH=$(".main-content").height();
		var _parent=$(window.parent.document);
        	_parent.find('body').css('height',(myiframeH+150)+'px');
			_parent.find('.main-position').css('height',(myiframeH+100)+'px');
    	};
    	$('.main-content').resize(function(){
			getHeight();
		});
    	function del(my){
    		$(my).parent().parent().remove();
    	}
    	$(document).ready(function(){
    		var data = parent.data;
    		for(var i = 0 ; i < data.length ; i++){
    			var html = "";
    			html += "<tr><td><input type = 'hidden' name = 'inbounds[" + i + "].id' value = '" + data[i].id + "' >" + data[i].projectcode + "</td><td>" + data[i].projectname + "</td><td>" + (data[i].nd) + "</td>"
    			+ "<td>" + (data[i].canDispatchnumber) + "</td>"
    			+ "<td><input type = 'text' name = 'inbounds[" + i + "].dispatchnumber' placeholder = '" + (data[i].canDispatchnumber) + "'>"
    			+ "<td><input type='text' placeholder='1'name = 'inbounds[" + i + "].remark'></td>"
    			+ "<td><i class='icon-delImg' onclick='del(this)'></i></td>"
    			+ "</tr>";
    			$("#pre").prepend(html);
    		}
    		if(data){
    			$("#single3").val(data[0].printer);
    			$("#single3").change(function(){
    				layer.msg("印刷厂不能更改");
    				$("#single3").val(data[0].printer);
    			})
    		}
    	})
    	function validateCallback(){
    		var bo = true;
    		if(!$("div.fuzzy-query").getVal()){
    			parent.layer.msg("请选择收件部门");
    			return false;
    		}
    		var $tr = $("#pre").find("tr");
    		var length = $tr.length;
    		if(length < 1){
    			parent.layer.msg("没有合同需要配送");
    			return false;
    		}
    		for(var i = 0 ; i < length ; i++){
    			debugger
    			var can = $($tr[i]).find("td").eq(3).text();
    			var sr = $($tr[i]).find("td").eq(4).find("input").val();
    			var code = $($tr[i]).find("td").eq(5).find("input").val().split(";");
    			if(isNaN(sr)){
    				parent.layer.msg("本次配送数量只能输入数字");
    				return false;
    			}
    			if(sr * 1 > can * 1){
    				parent.layer.msg("本次配送数量不能超过可配送数量");
    				return false;
    			}
    			if(sr * 1 != code){
    				parent.layer.msg("请输入合理的配送编号，配送编号按';'切割后的长度应该与本次配送数量相等。")
    				return false;
    			}
    		}
    		return bo;
    	} 
    	function submitCallback(){
    		parent.layer.msg("配送成功");
    		parent.goUrl("contractDistribution.html");
    	}
	</script>
	<script src="js/jquery-validation/1.11.0/jquery.validate.min.js" type="text/javascript"></script>
	<script type="text/javascript" src = "js/submit.js"></script>
	<script type="text/javascript" src = "js/validate.js"></script>
</body>
</html>